package com.gdyx.app.web.svc.impl;

import com.gdyx.app.web.dao.MpsDeptUserDao;
import com.gdyx.app.web.model.MpsDeptUser;
import com.gdyx.app.web.svc.MpsDeptUserSvc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * Created by Y_Coffee on 2017/8/3.
 */
@Service
public class MpsDeptUserSvcImpl implements MpsDeptUserSvc {
    @Autowired
    MpsDeptUserDao mpsDeptUserDao;

    @Override
    public void save(MpsDeptUser o) {
        mpsDeptUserDao.save(o);
    }

    @Override
    public void saveOrUpdate(MpsDeptUser o) {
        mpsDeptUserDao.saveOrUpdate(o);
    }

    @Override
    public void delete(String id) {
        mpsDeptUserDao.delete(id);
    }

    @Override
    public void update(MpsDeptUser o) {
        mpsDeptUserDao.update(o);
    }

    @Override
    public int count(Map<String, Object> map) {
        return mpsDeptUserDao.count(map);
    }

    @Override
    public List<MpsDeptUser> findDeptUserByUid(String id) {
        return mpsDeptUserDao.findDeptUserByUid(id);
    }

    @Override
    public List<MpsDeptUser> findDeptUserByDid(String id) {
        return mpsDeptUserDao.findDeptUserByDid(id);
    }

    @Override
    public void deleteByDid(String id) {
        mpsDeptUserDao.deleteByDid(id);
    }

    @Override
    public void deleteByUid(String id) {
        mpsDeptUserDao.deleteByUid(id);
    }

    @Override
    public void setDeptUser(String ids, String deptId, String Ownerid) {
        mpsDeptUserDao.deleteByDid(deptId);
        if(StringUtils.isEmpty(ids)){
            return;
        }
        String[] userIds = ids.split(",");
        //添加
        for (String userId : userIds) {
            //create
            MpsDeptUser mDeptUser=new MpsDeptUser();
            mDeptUser.setId(UUID.randomUUID().toString().toUpperCase().trim());
            mDeptUser.setUserId(userId);
            mDeptUser.setDeptId(deptId);
            mDeptUser.setCreateOwner(Ownerid);
            mDeptUser.setCreateTime(new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()));
            mpsDeptUserDao.save(mDeptUser);
        }
    }
}
